//
//  DnpChooseAlbumDelegate.m
//  dnp_plugin
//
//

#import "DnpChooseAlbumDelegate.h"

@implementation DnpChooseAlbumDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    if (image) {
        BOOL isCameraOpen = (picker.sourceType == UIImagePickerControllerSourceTypeCamera);
        
        NSData *imageBytes = UIImageJPEGRepresentation(image, 0.8);
        
        self.result(@{
            @"imageBytes": imageBytes ? imageBytes : [NSNull null],
            @"isCameraOpen": @(isCameraOpen)
        });
        [picker dismissViewControllerAnimated:YES completion:nil];
    }
}

@end
